package main

import "fmt"

//实现一个迭代器
func main() {

	s := []int{1, 5, 4, 7, 3, 4}
	i := &Iterator{
		Data: s,
	}
	for i.HasNext() {
		fmt.Println(i.Next())
	}
}

type Iterator struct {
	Data  []int
	index int
}

func (this *Iterator) HasNext() bool {
	if this.Data == nil || len(this.Data) < 1 {
		return false
	}
	return this.index < len(this.Data)
}

func (this *Iterator) Next() interface{} {
	defer func() {
		this.index++
	}()

	return this.Data[this.index]

}
